<%@ page contentType="text/html;charset=UTF-8" language="java"  pageEncoding="UTF-8" %>
<html>
<head>
    <title>登录页面</title>
    <script src="static/js/jquery-3.0.0.min.js" type="text/javascript"></script>
</head>
<body>
<form >
    <label for="userName">用户名:</label>
    <input type="text" name="userName" id="userName" placeholder="请输入用户名...">
    <br>
    <label for="userPassword">密&ensp;&ensp;码:</label>
    <input type="password" name="userPassword" id="userPassword" placeholder="请输入密码...">
    <br>
    <input type="button" value="登录">
    <hr>

</form>
<script>
    $(function(){
         $("[type=button]").click(function () {
            let userName = $("#userName").val();
            let userPassword = $("#userPassword").val();
            $.ajax({
               url:"${pageContext.request.contextPath}/doLogin" ,
                type:"POST",
                data:JSON.stringify({"userName":userName,"userPassword":userPassword}),
                dataType:"json",
                contentType:"application/json;charset=UTF-8",
                beforeSed:function () {
                            return true;
                },
                success:function (result) {
                   if(result.success){
                       location.href="${pageContext.request.contextPath}/index";
                   }
                } ,
                error:function (error) {
                    console.log(error)
                }


            })
         })
    })
</script>
</body>
</html>
